//logs.js
const { url } = require('../../config/index.js') // 接口请求地址
const app = getApp() //获取应用实例

Page({
  data: {
    shopLists: [] // 店铺列表
  },
  // 获取咖啡店列表
  getCafeShop(longitude, latitude) {
    wx.showLoading({mask: true})
    wx.request({
      url: url + 'ServShop/getAllCoffeeShop.action',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        COORDINATE: longitude + ',' + latitude
      },
      success: res => {
        wx.hideLoading()
        console.log(res.data)
        if (res.data.STATUS_CODE === 1) {
          this.setData({
            shopLists: res.data.RESULT_DATA
          })
        }
      }
    })
  },
  // 原生地图
  nativeLocation (e) {
    let info = e.currentTarget.dataset.pos
    wx.openLocation({
      name: info.SHOP_NAME,
      address: info.ADDRESS,
      latitude: Number(info.LATITUDE),
        longitude: Number(info.LONGITUDE),
      scale: 28
    })
  },
  // 跳转咖啡店
  jumpToShop (e) {
    let shopinfo = e.currentTarget.dataset.shopinfo
    wx.setStorageSync('shopinfo', shopinfo)
    wx.redirectTo({
      url: "/pages/shop/shop?shopid=" + shopinfo.COMP_ID + "&shopname=" + shopinfo.SHOP_NAME
    })
  },
  onLoad: function () {
    var location = wx.getStorageSync('location')
    if (location){
      this.getCafeShop(location.longitude, location.latitude)
    }

  }
})
